package com.glsc.ngateway.platform.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.glsc.ngateway.common.api.flowable.resp.ResponseSituationDto;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.Appendix;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Entity
@Data
@Table(name = "t_gw_flow_form_dev_manage")
@org.hibernate.annotations.Table(appliesTo = "t_gw_flow_form_dev_manage",comment = "需求管理流程form表单")
public class FlowFormDevManage implements Serializable {

    @ApiModelProperty(value = "流程ID")
    @Id
//    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "process_id", columnDefinition = "varchar(60) comment '唯一编号'")
    private String processId;

    @Column(name = "gitee_issue_id", columnDefinition = "varchar(60) comment 'gitee编号'")
    private String giteeIssueId;

    @ApiModelProperty(value = "流程创建时间")
    @org.hibernate.annotations.CreationTimestamp
    @Column(name = "process_create_time", columnDefinition = "datetime comment '发起时间'")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime processCreateTime;

//    @ApiModelProperty(value = "需求发生时间")
//    @Column(name = "demand_happen_time", columnDefinition = "datetime comment '需求发生时间'")
//    @DateTimeFormat(pattern = "yyyy-MM-dd")
//    @JsonFormat(pattern = "yyyy-MM-dd")
//    @JsonSerialize(using = LocalDateSerializer.class)
//    @JsonDeserialize(using = LocalDateDeserializer.class)
//    private LocalDate demandHappenTime;

    /**
     * 流程标题
     */
    @ApiModelProperty(value = "流程标题")
    @Column(name = "process_title", columnDefinition = "varchar(1024) comment '流程标题'")
    String processTitle;

    /**
     * 需求标题
     */
    @ApiModelProperty(value = "需求标题")
    @Column(name = "demand_title", columnDefinition = "varchar(1024) comment '需求标题'")
    String demandTitle;

    @ApiModelProperty(value = "内部需求")
    @Column(name = "demand_inner", columnDefinition = "varchar(2) comment '是否内部需求  字典项yesno'")
    String demandInner;

    @ApiModelProperty(value = "需求优先级")
    @Column(name = "demand_priority", columnDefinition = "varchar(2) comment '需求优先级'")
    String demandPriority;

    /**
     * 发起人姓名
     */
    @ApiModelProperty(value = "发起人姓名")
    @Column(name = "flow_create_operator_name", columnDefinition = "varchar(30) comment '发起人姓名'")
    String flowCreateOperatorName;

    /**
     * 发起人账号oa
     */
    @ApiModelProperty(value = "发起人账号oa")
    @Column(name = "flow_create_operator_account", columnDefinition = "varchar(30) comment '发起人账户'")
    String flowCreateOperatorAccount;

    @ApiModelProperty(value = "发起人部门名称")
    @Column(name = "flow_creator_department", columnDefinition = "varchar(30) comment '发起人部门名称'")
    String flowCreatorDepartment;

    /**
     * 系统名称
     */
    @ApiModelProperty(value = "所属系统")
    @Column(name = "system_name", columnDefinition = "varchar(200) comment '所属系统，从it网关取'")
    private String systemName;

    /**
     * 系统代码
     */
    @ApiModelProperty(value = "系统代码")
    @Column(name = "system_code", columnDefinition = "varchar(30) comment '系统名称，从it网关取，后续关联团队人员'")
    private String systemCode;

    /**
     * 系统管理员姓名
     */
    @ApiModelProperty(value = "项目经理姓名")
    @Column(name = "system_admin_name", columnDefinition = "varchar(30) comment '项目经理姓名'")
    private String systemAdminName;


    /**
     *系统管理员账号oa
     */
    @ApiModelProperty(value = "项目经理账号oa")
    @Column(name = "system_admin_account", columnDefinition = "varchar(30) comment '项目经理账户'")
    private String systemAdminAccount;

    /**
     * 系统管理员姓名
     */
    @ApiModelProperty(value = "系统归属部门")
    @Column(name = "system_belong_department", columnDefinition = "varchar(50) comment '系统归属部门'")
    private String systemBelongDepartment;

    @ApiModelProperty(value = "需求分类 字典")
    @Column(name = "demand_class", columnDefinition = "varchar(10) comment '需求分类'")
    private String demandClass;

    @ApiModelProperty(value = "需求分级 字典")
    @Column(name = "demand_grade", columnDefinition = "varchar(10) comment '需求分级'")
    private String demandGrade;

    @ApiModelProperty(value = "需求背景")
    @Column(name = "demand_background", columnDefinition = "Text comment '需求背景'")
    private String demandBackground;

    @ApiModelProperty(value = "需求目标")
    @Column(name = "demand_purpose", columnDefinition = "Text comment '需求目标'")
    private String demandPurpose;

    @ApiModelProperty(value = "需求来源")
    @Column(name = "demand_from", columnDefinition = "Text comment '需求来源'")
    private String demandFrom;

    @ApiModelProperty(value = "需求关联方名称")
    @Column(name = "demand_relate_name", columnDefinition = "varchar(30) comment '需求关联方姓名'")
    private String demandRelateName;

    @ApiModelProperty(value = "需求关联方账号oa")
    @Column(name = "demand_relate_account", columnDefinition = "varchar(30) comment '项目经理账户'")
    private String demandRelateAccount;

    @ApiModelProperty(value = "需求概述")
    @Column(name = "demand_summary", columnDefinition = "Text comment '需求概述'")
    private String demandSummary;

    @ApiModelProperty(value = "需求边界")
    @Column(name = "demand_boundary", columnDefinition = "Text comment '需求边界'")
    private String demandBoundary;

    @ApiModelProperty(value = "需求风险")
    @Column(name = "demand_risk", columnDefinition = "Text comment '需求风险'")
    private String demandRisk;

    @ApiModelProperty(value = "需求详述")
    @Column(name = "demand_detail", columnDefinition = "Text comment '需求详述'")
    private String demandDetail;

    @ApiModelProperty(value = "是否立项 字典")
    @Column(name = "demand_setup", columnDefinition = "varchar(10) comment '是否立项'")
    private String demandSetup;

    @ApiModelProperty(value = "立项结果")
    @Column(name = "demand_setup_result", columnDefinition = "Text comment '立项结果'")
    private String demandSetupResult;

    @ApiModelProperty(value = "评审人员oa账号")
    @Transient
//    @Column(name = "demand_ok_account", columnDefinition = "varchar(10) comment '评审人员oa账号'")
    private List<String> demandOkAccountList;

    @ApiModelProperty(value = "是否需要OA合规评审")
    @Column(name = "demand_need_oa_ok", columnDefinition = "varchar(10) comment '是否需要OA合规评审'")
    private String demandNeedOaOk;

    @ApiModelProperty(value = "OA合规评审流程")
    @Column(name = "demand_oa_ok_title", columnDefinition = "varchar(200) comment 'OA合规评审流程'")
    private String demandOaOkTitle;

    @ApiModelProperty(value = "OA合规评审结果")
    @Column(name = "demand_oa_ok_result", columnDefinition = "varchar(10) comment 'OA合规评审结果'")
    private String demandOaOkResult;

    @ApiModelProperty(value = "所需工时")
    @Column(name = "demand_work_time", columnDefinition = "varchar(100) comment '所需人天'")
    private String demandWorkTime;

    @ApiModelProperty(value = "解决方案")
    @Column(name = "demand_solution", columnDefinition = "Text comment '解决方案'")
    private String demandSolution;

    @ApiModelProperty(value = "验收评价")
    @Column(name = "evalue_score", columnDefinition = "varchar(2) comment '验收评价'")
    private String evalueScore;

    @ApiModelProperty(value = "需求设计评审人员账号")
    @Transient
//    @Column(name = "demand_result", columnDefinition = "Text comment '需求设计评审人员'")
    private List<String> demandDesignAccountList;


    @ApiModelProperty(value = "需求文件")
    @Column(name = "demand_doc_id_list", columnDefinition = "varchar(300) comment '需求报告附件列表'")
    private String demandDocIdList;

    @ApiModelProperty(value = "需求文件")
    @Transient
    private List<Appendix> demandDocList;

    @ApiModelProperty(value = "设计文件")
    @Column(name = "demand_design_doc_id_list", columnDefinition = "varchar(300) comment '需求报告附件列表'")
    private String demandDesignDocIdList;

    @ApiModelProperty(value = "设计文件")
    @Transient
    private List<Appendix> demandDesignDocList;

    @ApiModelProperty(value = "测试用例文件")
    @Column(name = "demand_test_instance_doc_id_list", columnDefinition = "varchar(300) comment '需求报告附件列表'")
    private String demandTestInstanceDocIdList;

    @ApiModelProperty(value = "测试用例文件")
    @Transient
    private List<Appendix> demandTestInstanceDocList;

    @ApiModelProperty(value = "测试报告文件")
    @Column(name = "demand_test_report_doc_id_list", columnDefinition = "varchar(300) comment '需求报告附件列表'")
    private String demandTestReportDocIdList;

    @ApiModelProperty(value = "测试报告文件")
    @Transient
    private List<Appendix> demandTestReportDocList;

//    @ApiModelProperty(value = "部署文件")
//    @Column(name = "demand_online_doc_id_list", columnDefinition = "varchar(300) comment '需求报告附件列表'")
//    private String demandOnlineDocIdList;
//
//    @ApiModelProperty(value = "部署文件")
//    @Transient
//    private List<Appendix> demandOnlineDocList;

    @ApiModelProperty(value = "是否完成 ")
    @Column(name = "is_close", columnDefinition = "int(2) comment '是否完成0 未完成 1已完成'")
    private int isClose = 0;

    @ApiModelProperty(value = "是否删除 ")
    @Column(name = "is_delete", columnDefinition = "int(2) comment '是否删除0 未删除 1已删除'")
    private int isDelete = 0;

    @ApiModelProperty(value = "当前审批")
    @Column(name = "current_node", columnDefinition = "varchar(100) comment '当前节点'")
    private String currentNode;

    @ApiModelProperty(value = "当前审批过节点 ")
    @Column(name = "current_node_passed", columnDefinition = "varchar(100) comment '当前审批过的节点'")
    private String currentNodePassed;

    @ApiModelProperty(value = "创建时间")
    @Column(name = "insert_time", columnDefinition = "datetime comment '创建时间'")
    @org.hibernate.annotations.CreationTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    protected LocalDateTime insertTime;

    @ApiModelProperty(value = "更新时间")
    @Column(name = "update_time", columnDefinition = "datetime comment '更新时间'")
    @org.hibernate.annotations.UpdateTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    protected LocalDateTime updateTime;


    /**
     *
     * TODO 暂时这样
     * * * * */
    public static FlowFormDevManage instance(ResponseSituationDto r) {
        return new FlowFormDevManage();
    }

    /**
     * 整改措施
     */
    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(name = "process_id", referencedColumnName = "process_id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    @Where(clause = " be_deleted=0 ")//仅未删除状态的
    @ApiModelProperty(value = "整改明细")
    List<FlowFormTaskDetail> detail;
}
